import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/home/Home.vue";
import Discover from "../views/discover/discover.vue";
import Video from "../views/video/video.vue";
import Personalrecom from "../views/discover/personalrecom.vue";
import Playlist from "../views/discover/playlist.vue";
import PlayListDetail from "../views/playlistdetail/PlayListDeatail.vue";
import SearchList from "../views/search/SearchList.vue";
import AlbumDetail from "../views/album/albumDetail.vue";
import ArtistDetail from "../views/artist/ArtistDetail.vue";
import UserDetail from "../views/user/UserDetail.vue";
import VideoDetail from "../views/video/VideoDetail.vue";
import Login from "../views/home/login.vue";
import store from "@/store/index";
import TopList from "@/views/discover/topList.vue";
import ArtistList from "@/views/discover/artistlist.vue";
import ZuiXin from "@/views/discover/zuixin.vue";
import MV from "@/views/video/MvView.vue";
import VideoView from "@/views/video/videoView.vue";
import AllMv from "@/views/video/AllMv.vue"
import TopMv from "@/views/video/TopMv.vue"
import PersonalFm from "@/views/user/PersonalFm.vue"
import RecomSong from "@/views/user/Recomsong.vue"
import HistoryList from "@/views/historyplay/Historyplay.vue"
import SubScribe from "@/views/user/subscribe/SubscribeView.vue"
import SubAlbum from "@/views/user/subscribe/SubAlbum.vue"
import SubArtist from "@/views/user/subscribe/SubArtist.vue"
import SubMv from "@/views/user/subscribe/SubMv.vue"
import UserEdit from "@/views/user/UserEdit.vue"
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    component: Home,
    redirect: "/discover/personalrecom",
    children: [
      {
        path: "/discover",
        component: Discover,
        redirect: "/discover/personalrecom",
        children: [
          {
            path: "/discover/personalrecom",
            component: Personalrecom,
            meta: { title: "个性推荐" },
          },
          {
            path: "/discover/playlist",
            component: Playlist,
            meta: { title: "歌单列表" },
          },
          {
            path: "/discover/toplist",
            component: TopList,
            mate: { title: "排行榜" },
          },
          {
            path: "/discover/artistlist",
            component: ArtistList,
            mate: { title: "歌手" },
          },
          {
            path: "/discover/zuixin",
            component: ZuiXin,
            mate: { title: "最新音乐" },
          },
        ],
      },
      {
        path: "videoview",
        component: VideoView,
        redirect: "/video",
        mate: { check: false },
        children: [
          {
            path: "/video",
            component: Video,
            meta: { check: false, title: "视频" },
          },
          { path: "/mv", component: MV, meta: { check: false, title: "Mv" } },
        ],
      },
      {
        path:'subscribe',
        component:SubScribe,
        redirect:'/sub-album',
        mate:{check:true},
        children:[
          {
            path:'/sub-album',
            component:SubAlbum,
            meta:{check:true,title:'专辑'}
          },
          {
            path:'/sub-artists',
            component:SubArtist,
            meta:{check:true , title:'歌手'},
          },
          {
            path:'/sub-mv',
            component:SubMv,
            meta:{check:true,title:'MV'}
          }
        ]
      },
      {
        path: "/playlistdetail/:id",
        component: PlayListDetail,
        meta: { title: "歌单" },
      },
      {
        path: "/albumdetail/:id",
        component: AlbumDetail,
        meta: { title: "专辑" },
      },
      {
        path: "/artistdetail/:id",
        component: ArtistDetail,
        meta: { title: "歌手主页" },
      },
      {
        path: "/userdetail/:id",
        component: UserDetail,
        meta: { title: "用户主页" },
      },
      {
        path: "/videodetail/:type/:id",
        component: VideoDetail,
        meta: { check: false, title: "视频" },
      },
      {
        path: "/search",
        component: SearchList,
        props: (route) => ({ keywords: route.query.keywords }),
        meta: { title: "搜索结果" },
      },
      {
        path:"/allmv",
        component:AllMv,
        meta:{check : false , title :'全部MV'}
      },
      {
        path:'/topmv',
        component:TopMv,
        meta:{check: false , title :'Mv排行'}
      },
      {
        path:'/personalfm',
        component:PersonalFm,
        meta:{check : true , title :'私人FM'}
      },
      {
        path:'/recomsongs',
        component:RecomSong,
        meta:{check:true,title:'每日推荐'}
      },
      {
        path:'/historyplay',
        component:HistoryList,
        meta:{check:false, title : '最近播放'}
      },
      {
        path:'/useredit',
        component:UserEdit,
        mate:{check:true,title : '编辑信息'}
      }
    ],
  },
  { path: "/login", component: Login, meta: { check: false, title: "登录" } },
];

const router = new VueRouter({
  routes,
});

router.beforeEach((to, from, next) => {
  if (to.meta.check === true) {
    if (store.state.isLogin === true) next();
    else {
      Vue.prototype.$message.error("需要登录");
      next("/login");
    }
  } else {
    next();
  }
});

export default router;
